package cn.hzking.gjmall.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import java.util.Timer;
import java.util.TimerTask;

import static android.content.Context.INPUT_METHOD_SERVICE;

/**
 * Created by Administrator on 2017/3/7.
 */

public class InputManager {

    /**
     * 隐藏软键盘
     *
     * @param context
     * @param view
     */
    public static void hideSoftInput(Context context, View view) {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(INPUT_METHOD_SERVICE);//隐藏输入框
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        view.clearFocus();

    }

    /**
     * 显示软键盘
     *
     * @param ctx
     * @param view
     */
    public static void showSoftInput(final Context ctx, final View view) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
                           public void run() {
                               InputMethodManager inputManager =
                                       (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
                               inputManager.showSoftInput(view, 0);
                           }
                       },
                200);
    }
}
